package com.ruoyi.cderp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.cderp.domain.ProductCategory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cderp.domain.CategoryProperty;
import com.ruoyi.cderp.service.ICategoryPropertyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品类目和商品属性关系Controller
 *
 * @author ruoyi
 * @date 2025-03-17
 */
@RestController
@RequestMapping("/system/CategoryProperty")
public class CategoryPropertyController extends BaseController
{
    @Autowired
    private ICategoryPropertyService categoryPropertyService;

    /**
     * 查询商品类目和商品属性关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:CategoryProperty:list')")
    @GetMapping("/list")
    public TableDataInfo list()
    {
        List<ProductCategory> list = categoryPropertyService.selectProductCategoryList();
        return getDataTable(list);
    }

    /**
     * 获取商品类目和商品属性关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:CategoryProperty:query')")
    @GetMapping(value = "/{pid}")
    public AjaxResult getInfo(@PathVariable("pid") String pid)
    {
        return success(categoryPropertyService.selectCategoryPropertyPId(pid));
    }

    /**
     * 新增商品类目和商品属性关系
     */
    @PreAuthorize("@ss.hasPermi('system:CategoryProperty:add')")
    @Log(title = "商品类目和商品属性关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CategoryProperty categoryProperty)
    {
        return toAjax(categoryPropertyService.insertCategoryProperty(categoryProperty));
    }

    /**
     * 修改商品类目和商品属性关系
     */
    @PreAuthorize("@ss.hasPermi('system:CategoryProperty:edit')")
    @Log(title = "商品类目和商品属性关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CategoryProperty categoryProperty)
    {
        return toAjax(categoryPropertyService.updateCategoryProperty(categoryProperty));
    }
}
